<template>
  <div>
    <div class="params">
      <el-row>
        <label>页面URI:</label>
        <el-select  style="width:160px" v-model="param.pageUri" @change="loadData">
          <el-option v-for="item in pageUris " :key="item.value" :label="item.label"
                     :value="item.value">
          </el-option>
        </el-select>
        <el-button type="primary" class="el-icon-sort" @click="sync()">同步</el-button>
      </el-row>
    </div>
    <el-table :data="tableData" border highlight-current-row stripe style="width: 100%">
      <el-table-column prop="constantId" label="ID"></el-table-column>
      <el-table-column prop="pageUri" label="页面URI"></el-table-column>
      <el-table-column prop="fieldTitle" label="常量作用"></el-table-column>
      <el-table-column prop="fieldValue" label="常量值"></el-table-column>
      <el-table-column prop="fieldName" label="常量名"></el-table-column>
      <el-table-column prop="nick" label="操作">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="text" size="small">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="修改" :modal-append-to-body="false" :visible.sync="editDialog" >
      <el-form>
        <el-form-item label="页面URI:">
          <el-input  v-model="editDialogParam.pageUri"></el-input>
        </el-form-item>
        <el-form-item label="常量作用:">
          <el-input  v-model="editDialogParam.fieldTitle"></el-input>
        </el-form-item>
        <el-form-item label="常量名:">
          <el-input  v-model="editDialogParam.fieldName"></el-input>
        </el-form-item>
        <el-form-item label="常量值:">
          <el-input  v-model="editDialogParam.fieldValue"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialog = false">取 消</el-button>
        <el-button type="primary" @click="submitEdit()" >确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {ajax,modifyConstants,synConstants,selOsConstant} from "../../data/service";

  export default {
        name: "versionConstant",
      data(){
          return {
            pageUris:[
              {
                label:"iOS审核",
                value:"iOSTEST"
              },
              {
                label:"Android",
                value:"Android"
              },
              {
                label:"iOS",
                value:"iOS"
              }
            ],
            param:{
              pageUri:'Android'//默认安卓的
            },
            tableData:[],
            editDialog:false,
            editDialogParam:{
              constantId:'',
              pageUri:'',
              fieldTitle:'',
              fieldName:'',
              fieldValue:''
            }
          }
      },
    created(){
      this.loadData();
    },
    mixins:[ajax],
      methods:{
        loadData(){
          this.doajax(selOsConstant,{pageUri:this.param.pageUri},resp=>{
            this.tableData = resp.data;
          });
        },
        edit(row){
          this.editDialog=true;
          this.editDialogParam=row;
        },
        submitEdit(){
          this.doajax(modifyConstants,this.editDialogParam,(resp) => {
            this.success("修改成功");
            this.loadData();
            this.editDialog=false;
          });
        },
        sync(){
          this.doajax(synConstants,{},(resp)=>{
            this.success("操作成功");
          })
        }
      }
    }
</script>

<style scoped>

</style>
